package base.json.fastjson.demo02;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.PropertyFilter;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.time.LocalDateTime;

@Slf4j
public class Client {

    /**
     * PropertyFilter 自定义属性过滤器使用
     */
    @Test
    public void testCase1(){
        PropertyFilter filter = new PropertyFilter() {
            @Override
            public boolean apply(Object object, String name, Object value) {
                if ("id".equals(name)) {
                    int id = ((Integer) value).intValue();
                    return id>=100;
                }
                return false;
            }
        };

        User zhangsan = new User(101, "zhangsan", 18, LocalDateTime.now());
        String s1 = JSON.toJSONString(zhangsan, filter);
        log.info("s1----------->{}",s1);//s1----------->{"id":101}

    }

}
